
from rss import RssReader


reader = RssReader("http://www.xroxy.com/proxyrss.xml")
reader.set_item_tag("prx:proxy")
reader.add_item_desc(remote_name = "prx:ip" , local_name="ip",type=str)
reader.add_item_desc(remote_name = "prx:port", local_name = "port" , type=int)
reader.add_item_desc(remote_name = "prx:country_code" , local_name = "country" , type=str)
reader.add_item_desc(remote_name = "prx:ssl" , local_name = "ssl" , type=bool)


print("Proxies in the USA that support ssl")
for item in reader.read():
    if item.country == "US" and item.ssl == True:
        print( "%s:%s" % (item.ip ,item.port))
    


print('-' * 30)

reader = RssReader("http://feeds.digg.com/digg/news/popular.rss")
reader.set_item_tag("item")
reader.add_item_desc(remote_name = "title" , local_name="title",type=unicode) \
      .add_item_desc(remote_name = "description", local_name = "desc" , type=unicode) \
      .add_item_desc(remote_name = "pubDate" , local_name = "date" , type=unicode) \
      .add_item_desc(remote_name = "digg:diggCount" , local_name = "diggs" , type=int) \
      .add_item_desc(remote_name = "digg:commentCount" , local_name = "comments" , type=int) \
      .add_item_desc(remote_name = "digg:username" , local_name = "by" , type=unicode) \

print("First 10 digg stories - sorted by digg count")
items = reader.read()
items.sort( key = lambda item : item.diggs , reverse = True)
for item in items[:10]:
    print( "\"%s\", by %s, comments: %d, diggs: %d" % (item.title ,item.by ,item.comments,item.diggs))
    
    


